package edu.nwpu.zya.coreops.modules.dashboard.service.impl;

import edu.nwpu.zya.coreops.common.utils.Constant;
import edu.nwpu.zya.coreops.modules.alert.dao.RuleDao;
import edu.nwpu.zya.coreops.modules.dashboard.entity.AlertCountEntity;
import edu.nwpu.zya.coreops.modules.dashboard.service.DashboardService;
import edu.nwpu.zya.coreops.modules.dashboard.entity.InstanceCountEntity;
import edu.nwpu.zya.coreops.modules.resource.dao.AppDao;
import edu.nwpu.zya.coreops.modules.resource.dao.EcsDao;
import edu.nwpu.zya.coreops.modules.resource.dao.RdsDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("dashboardService")
public class DashboardServiceImpl implements DashboardService {
    @Autowired
    private EcsDao ecsDao;

    @Autowired
    private RdsDao rdsDao;

    @Autowired
    private AppDao appDao;

    @Autowired
    private RuleDao ruleDao;

    @Override
    public InstanceCountEntity getInstanceCountByType(Long userId, Integer type) {
        InstanceCountEntity instanceCountEntity =new InstanceCountEntity();
        if(type== Constant.InstanceType.ECS.getValue()){
            instanceCountEntity =ecsDao.getInstanceCount(userId);
        }else if(type==Constant.InstanceType.RDS.getValue()){
            instanceCountEntity =rdsDao.getInstanceCount(userId);
        }else {
            instanceCountEntity=appDao.getInstanceCount(userId);
        }
        return instanceCountEntity;
    }

    @Override
    public AlertCountEntity getAlertCount(Long userId) {
        if(userId.intValue()==Constant.SUPER_ADMIN){
            return ruleDao.getAllAlertCount();
        }else {
            return ruleDao.getAlertCountByUserId(userId);
        }
    }
}
